// js/darkmode.js
function toggleDarkMode() {
  document.body.classList.toggle('night-mode');
  const isDark = document.body.classList.contains('night-mode');
  localStorage.setItem('darkMode', isDark);
  
  // 更新所有页面上的按钮图标
  const darkModeBtns = document.querySelectorAll('.mode-toggle');
  darkModeBtns.forEach(btn => {
    btn.innerHTML = isDark ? 
      '<i class="fas fa-sun"></i>' : 
      '<i class="fas fa-moon"></i>';
  });
}

// 页面加载时检查用户偏好
function initDarkMode() {
  const darkMode = localStorage.getItem('darkMode') === 'true';
  if(darkMode) {
    document.body.classList.add('night-mode');
    
    // 更新所有页面上的按钮图标
    const darkModeBtns = document.querySelectorAll('.mode-toggle');
    darkModeBtns.forEach(btn => {
      btn.innerHTML = '<i class="fas fa-sun"></i>';
    });
  }
}

// 初始化
document.addEventListener('DOMContentLoaded', initDarkMode);